home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / EnterAct 3.5 / Drag_on Modules / hAWK programs / $ClipGlossary < prev    next >
Encoding:
Text File  |  1995-01-23  |  2.5 KB  |  104 lines  |  [TEXT/KEEN]

  1. #$ClipGlossary: a "magic clipboard" program that remembers and
  2. # expands glossary abbreviations.
  3. # To make an entry, Copy text of the form
  4. #     gloss name entry
  5. # with nothing before "gloss", one or more spaces or tabs after,
  6. # the single-word name for the entry, one or more space or tabs,
  7. # and then the entry proper, which can occupy more than one line.
  8. # To expand a glossary name, type the name, select and Copy it,
  9. # and then Paste after the menu bar flashes.
  10. # Takes no input, remembers all entries to the file "Glossary".
  11.  
  12. BEGIN {
  13.     GlossaryFile = STDPATH "Glossary";
  14.     LoadOldGlossary();
  15.     clipCharsToWatch = 32;
  16.     while (1) # run until <Command><period>...
  17.         {
  18.         # see if clipboard has changed
  19.         if ((newClip = getclip(clipCharsToWatch)) != oldClip)
  20.             {
  21.             oldClip = newClip;
  22.             
  23.             if (substr(newClip, 1,5) == "gloss")
  24.                 {
  25.                 fullClip = getclip(); # gets calling editor's private clip
  26.                 MakeNewEntry();
  27.                 }
  28.             else if (newClip in glossary)
  29.                 {
  30.                 fullClip = getclip(); # gets calling editor's private clip
  31.                 ExpandEntry();
  32.                 }
  33.             }
  34.         }
  35.     }
  36.  
  37. function LoadOldGlossary(    name, entry)
  38.     {
  39.     while (getline x < GlossaryFile > 0)
  40.         {
  41.         if (x == "ENTRY")
  42.             {
  43.             entry = ""
  44.             if (getline x < GlossaryFile > 0)
  45.                 {
  46.                 if (match(x, /^gloss[ \t]+/))
  47.                     {
  48.                     x = substr(x, RLENGTH+1);
  49.                     if (match(x, /^[^ \t]+/))
  50.                         {
  51.                         name = substr(x, 1, RLENGTH); # first word, the entry name
  52.                         match(x, /^[^ \t]+[ \t]+/); # after first word, the entry starts
  53.                         entry = substr(x, RLENGTH+1);
  54.                         while (getline x < GlossaryFile > 0)
  55.                             {
  56.                             if (x == "END")
  57.                                 break;
  58.                             else
  59.                                 entry = entry "\r" x;
  60.                             }
  61.                         glossary[name] = entry;
  62.                         }
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.     close(GlossaryFile);
  68.     }
  69.  
  70. function MakeNewEntry(    name, entry)
  71.     {
  72.     if (match(fullClip, /^gloss[ \t]+/))
  73.         {
  74.         fullClip = substr(fullClip, RLENGTH+1);
  75.         if (match(fullClip, /^[^ \t]+/)) # first word, the entry name
  76.             {
  77.             name = substr(fullClip, 1, RLENGTH);
  78.             match(fullClip, /^[^ \t]+[ \t]+/); # after first word, the entry starts
  79.             entry = substr(fullClip, RLENGTH+1);
  80.             glossary[name] = entry;
  81.             LogNewEntry();
  82.             # flash menu bar to signal something happened
  83.             beep(0);
  84.             }
  85.         }
  86.     }
  87.  
  88. function ExpandEntry(    out)
  89.     {
  90.     out = glossary[fullClip];
  91.     putclip(out);
  92.     oldClip = substr(out, 1, 32); # this would happen anyway next time...
  93.     # flash menu bar to signal something happened
  94.     beep(0);
  95.     }
  96.  
  97. function LogNewEntry()
  98.     {
  99.     print "ENTRY" >> GlossaryFile;
  100.     print "gloss " fullClip >> GlossaryFile;
  101.     print "END" >> GlossaryFile;
  102.     close (GlossaryFile);
  103.     }
  104.